package myJqueryTwo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//验证日期
public class WorkTwoRegex extends HttpServlet {
	static String regex = "([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|"
			+ "[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|"
			+ "((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))";

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String birth = req.getParameter("birth");
		PrintWriter out = resp.getWriter();
		out.write(birth.matches(regex) ? "true" : "false");

	}
	public static void main(String[] args) {
		System.out.println("123".matches(regex) ? "true" : "false");
		System.out.println("2018-01-01".matches(regex) ? "true" : "false");
	}
}
